package moodish.client;

import javax.swing.JOptionPane;

import moodish.client.gui.MoodishClientGui;
import moodish.client.user.User;
import moodish.comm.ClientSideMessage;


public class MoodishMessage {

	private MoodishClientGui gui;
	private String incomming ="";

	public MoodishMessage(MoodishClientGui gui) {
		this.gui = gui;
	}

	
	public void newMessage(ClientSideMessage message) {
		
		
		switch (message.getType()) {
		
		case DISCONNECTED:
			JOptionPane.showMessageDialog(null, "You are disconnected now!");
			break;
			
		case CONNECTED:
			
			break;
			
		case FRIENDSHIP:
			User u1 = new User(message.getSendersNickname());
			System.out.println("Sender nickname ----Z>>" + message.getSendersNickname());
			u1.setMood(message.getPayload());
			gui.getMainPanel().getFeedPane().addFeed(u1, message.getType(), gui);
			gui.getMainPanel().getFeedPane().updateFeed();
			break;
			
		case UNFRIENDSHIP:

			gui.getUser().getFriendmodel().removeFriend(message.getSendersNickname());
			
			break;
			
		case MOODISH_MESSAGE:
			User u = new User(message.getSendersNickname());
			u.setMood(message.getPayload());
			gui.getMainPanel().getFeedPane().addFeed(u, message.getType(), gui);
			gui.getMainPanel().getFeedPane().updateFeed();
			break;
			
		case ERROR:
				incomming = "error";
			break;
			
		default:
			break;
		}
	}

	public String recived() {
		return incomming;
	}

}
